package com.jxc.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class Sum extends HttpServlet {
    @Override
    // service()是请求处理的核心方法，无论是get请求方式，还是post请求方式都会被service（）方法处理
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String n1 = req.getParameter("n1") ;
//        int n = Integer.parseInt(n1);
//        int result = 0;
//        for (int i=0;i<=n;i++){
//           result = result + i;
//        }
//        PrintWriter out = resp.getWriter();
//        out.print("<h1>"+result+"</h1>");
        String add1 = req.getParameter("add1");
        String add2 = req.getParameter("add2");
        int n1 = Integer.parseInt(add1);
        int n2 = Integer.parseInt(add2);
        int result = n1+n2;
        PrintWriter out = resp.getWriter();
        out.print("<h1>Addition Calculator: </h1><br>");
        out.print("</h1>Calculation result:"+ result+"</h1><br>");
    }
}
